﻿using System;
using System.Collections.Generic;

namespace Shuba.Web.master
{
    public partial class branch_nip_so_list_excel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "application/vnd.ms-excel";

            string txtSearch = Request["txtSearch"];

            Shuba.Business.User _user = new Shuba.Business.User();
            var _bll = new Shuba.Business.BranchNipSOMap();
            var list = _bll.GetList(txtSearch);

            foreach (Shuba.Model.BranchNipSOMapInfo item in list)
            {
                List<Shuba.Model.UserInfo> ulist;

                ulist = _user.GetUserGroupName(item.NIP);
                foreach (Shuba.Model.UserInfo ui in ulist)
                {
                    item.USER_NAME = ui.Name;
                    item.GROUP_NAME += ui.GroupId + " - " + ui.GroupName + "<BR>";
                }
            }

            rep1.DataSource = list;
            rep1.DataBind();
        }

        protected void rep1_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
            //if (e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Item)
            //{
            //    string NIP = ((Shuba.Model.BranchNipSOMapInfo)(e.Item.DataItem)).NIP;
            //    string UName = "", Group = "";

            //    Shuba.Business.User _user = new Shuba.Business.User();
            //    List<Shuba.Model.UserInfo> list;

            //    list = _user.GetUserGroupName(NIP);
            //    foreach (Shuba.Model.UserInfo item in list)
            //    {
            //        UName = item.Name;
            //        Group += item.GroupId + " - " + item.GroupName + "<BR>";
            //    }

            //    System.Web.UI.WebControls.Label lblUserName = e.Item.FindControl("lblUserName") as System.Web.UI.WebControls.Label;
            //    System.Web.UI.WebControls.Label lblGroup = e.Item.FindControl("lblGroup") as System.Web.UI.WebControls.Label;

            //    lblUserName.Text = UName;//.Substring(0, UName.Length - 4);//if (AppN.Length > 0) AppN = AppN.Substring(0, AppN.Length - 4);
            //    lblGroup.Text = Group;
            //}
        }
    }
}
